<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="所属行业" prop="industryId">
        <div class="w-[200px]">
          <el-select class="flex-1" v-model="queryParams.industryId" placeholder="请选择所属行业" clearable>
            <el-option class="flex-1" v-for="item in industryList" :key="item.industryId" :label="item.name"
              :value="item.industryId" />
          </el-select>
        </div>
      </el-form-item>
      <el-form-item label="所属系统" prop="systemName">
        <el-input style="width: 200px;" v-model="queryParams.systemName" placeholder="请输入所属系统" clearable
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="所属单位" prop="merchantName">
        <el-input v-model="queryParams.merchantName" placeholder="请输入所属单位" clearable style="width: 200px"
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="商品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入商品名称" clearable style="width: 200px"
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="noticeList">
      <!-- 
        序号、商品名称、商品图片、投放形式、
        所属行业、所属系统、所属单位、单位地址、
        法人姓名、法人电话、单位电话、创建时间、
        状态、操作人员
        -->
      <el-table-column label="序号" align="center" type="index" width="55">
        <template #default="{ $index }">
          {{ (queryParams.currentPage - 1) * queryParams.pageSize + $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="投放单位" align="center" prop="merchantName" />
      <el-table-column label="商品名称" align="center" prop="productName" show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="商品图片" align="center" prop="image">
        <template #default="scope">
          <el-image style="width: 50px; height: 50px;" :src="scope.row.image" :preview-src-list="[scope.row.image]"
            preview-teleported>
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="投放形式" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="edit" @click="handleUpdate(scope.row)">投放形式</el-button>
        </template>
      </el-table-column>
      <el-table-column label="所属行业" align="center" prop="industryName" />
      <el-table-column label="所属系统" align="center" prop="systemName" />

      <el-table-column label="单位地址" align="center" prop="addressDetail" />
      <el-table-column label="法人姓名" align="center" prop="legalPersonName" />
      <el-table-column label="法人电话" align="center" prop="legalPersonPhone" />
      <el-table-column label="单位电话" align="center" prop="officeSpacePhone" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="状态" align="center" prop="isPublish">
        <template #default="scope">
          <span v-if="scope.row.isPublish == true">已发布</span>
          <span v-if="scope.row.isPublish == false">未发布</span>
        </template>
      </el-table-column>
      <el-table-column label="操作人员" align="center" prop="updateUserName" />

    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.currentPage"
      v-model:limit="queryParams.pageSize" @pagination="getList" />
    <!-- 添加或修改审核对话框 -->

    <!-- 
    特价商品投放详情：
    投放范围
    投放时间
    列表位置
    投放日期
    品类位置
    特价商品
    -->
    <!-- 
    
        // type 1新品 2特价 3普通
    if (route.meta.title == '广告商品') {
      data.queryParams.type = 3
    -->
    <el-dialog :title="titleName" v-model="open" width="780px" append-to-body>
      <el-form ref="noticeRef" :model="form" :rules="rules" label-width="80px">
        <el-row>

          <!-- 普通 -->
          <template v-if="data.queryParams.type == 3">
            <template v-if="form.isSort == 0">
              <el-col :span="12">
                <el-form-item label="投放范围" prop="scope">
                  <el-select v-model="form.scope" placeholder="">
                    <el-option v-for="item in scopeList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="广告类型" prop="categoryList">
                  <el-input value="普通广告" placeholder="请输入广告类型" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="列表位置" prop="positionList">
                  <el-input v-model="form.positionList" placeholder="请输入列表位置" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="投放时间" prop="timeList">
                  <el-input v-model="form.timeList" placeholder="请输入时间" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="品类位置" prop="categoryList">
                  <el-input v-model="form.categoryList" placeholder="请输入品类位置" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="投放日期" prop="dateList">
                  <el-input v-model="form.dateList" placeholder="请输入日期" />
                </el-form-item>
              </el-col>
            </template>
            <template v-if="form.isSort == 1">
              <el-col :span="12">
                <el-form-item label="投放范围" prop="scope">
                  <el-select v-model="form.scope" placeholder="">
                    <el-option v-for="item in scopeList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="广告类型" prop="categoryList">
                  <el-input value="竞价排名" placeholder="请输入广告类型" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="列表位置" prop="positionList">
                  <el-input v-model="form.positionList" placeholder="请输入列表位置" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="开始日期" prop="startDate">
                  <el-input v-model="form.startDate" placeholder="请输入开始日期" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="品类位置" prop="categoryList">
                  <el-input v-model="form.categoryList" placeholder="请输入品类位置" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="结束日期" prop="endDate">
                  <el-input v-model="form.endDate" placeholder="请输入结束日期" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="位置排名" prop="sort">
                  <el-input v-model="form.sort" placeholder="请输入位置排名" />
                </el-form-item>
              </el-col>
            </template>
          </template>
          <!-- 新品 -->
          <template v-if="data.queryParams.type == 1">
            <el-col :span="12">
              <el-form-item label="投放范围" prop="scope">
                <el-select v-model="form.scope" placeholder="">
                  <el-option v-for="item in scopeList" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="投放时间" prop="timeList">
                <el-input v-model="form.timeList" placeholder="请输入时间" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="列表位置" prop="positionList">
                <el-input v-model="form.positionList" placeholder="请输入列表位置" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="投放日期" prop="dateList">
                <el-input v-model="form.dateList" placeholder="请输入日期" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="品类位置" prop="dateList">
                <el-input value="新品发布" placeholder="请输入品类位置" />
              </el-form-item>
            </el-col>
          </template>
          <!-- 特价 -->
          <template v-if="data.queryParams.type == 2">
            <el-col :span="12">
              <el-form-item label="投放范围" prop="scope">
                <el-select v-model="form.scope" placeholder="">
                  <el-option v-for="item in scopeList" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="投放时间" prop="timeList">
                <el-input v-model="form.timeList" placeholder="请输入时间" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="列表位置" prop="positionList">
                <el-input v-model="form.positionList" placeholder="请输入列表位置" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="投放日期" prop="dateList">
                <el-input v-model="form.dateList" placeholder="请输入日期" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="品类位置" prop="dateList">
                <el-input value="特价商品" placeholder="请输入品类位置" />
              </el-form-item>
            </el-col>

          </template>


        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup name="Notice">

const categoryList = ref([])
let arr = []
const arr1 = [
  { title: "用户端云平台界面头条位", type: 1, checked: false },
  { title: "用户端云平台界面次条位", type: 2, checked: false },
  { title: "用户端医疗机构界面头条位", type: 3, checked: false },
  { title: "用户端医疗机构界面次条位", type: 4, checked: false },
  { title: "用户端护工抢单界面头条位", type: 5, checked: false },
  { title: "用户端护工抢单界面次条位", type: 6, checked: false },
  { title: "用户端状态查询界面头条位", type: 7, checked: false },
  { title: "用户端状态查询界面次条位", type: 8, checked: false },
  /*  */
  { title: "管理端医疗机构界面头条位", type: 9, checked: false },
  { title: "管理端医疗机构界面次条位", type: 10, checked: false },
  { title: "管理端日常经营界面头条位", type: 11, checked: false },
  { title: "管理端日常经营界面次条位", type: 12, checked: false },
  { title: "管理端生产物流界面头条位", type: 13, checked: false },
  { title: "管理端生产物流界面次条位", type: 14, checked: false },
];
const arr2 = [
  { title: "用户端云平台界面图片位", type: 1, checked: false },
  { title: "用户端医疗机构界面图片位", type: 2, checked: false },
  { title: "用户端护工抢单界面图片位", type: 3, checked: false },
  { title: "用户端状态查询界面图片位", type: 4, checked: false },
  /*  */
  { title: "管理端医疗机构界面图片位", type: 5, checked: false },
  { title: "管理端日常经营界面图片位", type: 6, checked: false },
  { title: "管理端生产物流界面图片位", type: 7, checked: false },
];

let scopeList = [
  { label: "所在地一公里内发布", value: 1 },
  { label: "所在区县内发布", value: 2 },
  { label: "所在市内发布", value: 3 },
  { label: "所在省内发布", value: 4 },
  { label: "所在全国内发布", value: 5 },
]

import {
  authApiIndustryList
} from "@/api/login.js";
const industryList = ref([])
function authApiIndustryListApi() {
  authApiIndustryList().then(
    (res) => {
      industryList.value = [...res];
    }
  );
}
onMounted(() => {
  authApiIndustryListApi()
})

import { ElMessageBox } from 'element-plus'

import {
  advertisementProductApisupervisedetail,
  advertisementProductApisuperviselist,
} from "@/api/backAdvertisementProduct/backAdvertisementProduct";
import { useRoute } from "vue-router";
const { proxy } = getCurrentInstance();
const noticeList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    currentPage: 1,
    pageSize: 10,
    type: 1,
  },
  rules: {
  },
});




const { queryParams, form, rules } = toRefs(data);

const route = useRoute()

console.log(route, 'route');
const titleName = ref(1)
// type 1新品 2特价 3普通
if (route.meta.title == '广告商品') {
  data.queryParams.type = 3
  titleName.value = '广告商品投放详情'
} else if (route.meta.title == '新品发布') {
  data.queryParams.type = 1
  titleName.value = '新品发布投放详情'
} else if (route.meta.title == '特价商品') {
  data.queryParams.type = 2
  titleName.value = '特价商品投放详情'
}

/** 查询审核列表 */
function getList() {
  loading.value = true;
  advertisementProductApisuperviselist(queryParams.value).then((response) => {
    noticeList.value = response.records;
    total.value = response.total;
    loading.value = false;
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 表单重置 */
function reset() {
  form.value = {
    "scope": 0,
    "sort": null,
    "startDate": "",
    "endDate": "",
    "positionList": [
    ],
    "categoryList": [
      {
        "systemProductCategoryId": "",
        "name": ""
      }
    ]
  };
  proxy.resetForm("noticeRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.currentPage = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加审核";
}

/**修改按钮操作 */
function handleUpdate(row) {
  console.log(row, 'row');

  reset();
  const advertisementProductId = row.advertisementProductId || ids.value;

  advertisementProductApisupervisedetail(advertisementProductId).then((response) => {
    form.value = response;
    // categoryList.value = response.categoryList
    open.value = true;
    title.value = "投放形式";
  });
}

getList();
</script>